//
//  NSDictionary+YYAdd.m
//  YYKit <https://github.com/ibireme/YYKit>
//
//  Created by ibireme on 13/4/4.
//  Copyright (c) 2015 ibireme.
//
//  This source code is licensed under the MIT-style license found in the
//  LICENSE file in the root directory of this source tree.
//

#import "NSDictionary+YYAdd.h"



@implementation NSDictionary (YYAdd)


/*
 isValidJSONObject
 
 顶层对象必须是NSArray或者NSDictionary
 
 所有的对象必须是NSString、NSNumber、NSArray、NSDictionary、NSNull的实例
 
 所有NSDictionary的key必须是NSString类型
 
 数字对象不能是非数值或无穷
 */
- (NSString *)jsonPrettyStringEncoded {
    if ([NSJSONSerialization isValidJSONObject:self]) {
        NSError *error;
        NSData *jsonData = [NSJSONSerialization dataWithJSONObject:self options:NSJSONWritingPrettyPrinted error:&error];
        NSString *json = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
        if (!error){
            return json;
        }
    }
    return nil;
}


@end
